import random
import Number

# 中国移动 1
# 中国联通 2
# 中国电信 3
mobile_prefixes = {
    '134': 1, '135': 1, '136': 1, '137': 1,
    '138': 1, '139': 1, '147': 1, '150': 1,
    '151': 1, '152': 1, '157': 1, '158': 1,
    '159': 1, '178': 1, '182': 1, '183': 1,
    '184': 1, '187': 1, '188': 1, '198': 1,
    '165': 1, '166': 1, '191': 1, '197': 1,
    '199': 1,

    '130': 2, '131': 2, '132': 2, '145': 2,
    '146': 2, '155': 2, '156': 2, '166': 2,
    '171': 2, '175': 2, '176': 2, '185': 2,
    '186': 2,
    '167': 2, '196': 2,

    '133': 3, '149': 3, '153': 3, '173': 3,
    '174': 3, '177': 3, '180': 3, '181': 3,
    '189': 3, '190': 3, '193': 3, '199': 3,
    '162': 3, '163': 3, '164': 3, '165': 3,
    '192': 3, '199': 3,
}



def get_operator(phone_number):
    prefix = phone_number[:3]
    return mobile_prefixes.get(prefix, 0)

def generate_phone_number():
    keys = list(mobile_prefixes.keys())
    randomKey = random.choice(keys)
    spcode = mobile_prefixes[randomKey]
    return randomKey + Number.randomNumber(8), spcode

def generate_spcode_phone_number(spcode):
    map = {}
    for key, value in mobile_prefixes.items():
        if value == spcode:
            map[key] = value
    keys = list(map.keys())
    randomKey = random.choice(keys)
    spcode = map[randomKey]
    return randomKey + Number.randomNumber(8), spcode

if __name__ == '__main__':
    phoneNumber,spcode = generate_phone_number()
    print(phoneNumber, spcode)
    mPhoneNumber=generate_spcode_phone_number(1)
    print(mPhoneNumber)